package jmine.tec.database.query.columns;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Coluna que trata de campos booleanos
 * 
 * @author lundberg
 */
public class BooleanColumn extends AbstractColumn {

    /**
     * Construtor
     * 
     * @param type type
     * @param name name
     */
    public BooleanColumn(int type, String name) {
        super(type, name);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String read(ResultSet rs) {
        try {
            Boolean value = rs.getBoolean(this.getName());
            return String.valueOf(value);
        } catch (SQLException e) {
            return super.read(rs);
        }
    }

    /**
     * {@inheritDoc}
     */
    public void setParameter(PreparedStatement st, int parameterIndex, String value) throws SQLException {
        Boolean bool = Boolean.parseBoolean(value);
        st.setBoolean(parameterIndex, bool);
    }
}
